import java.util.ArrayList;

import Jama.Matrix;

/**
 * 
 */

/**
 * @author legomez
 *
 */
public class hash32 {
	static double patrones[][] = 
	       {{1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,1},/*A*/
		   {1,1,1,1,0,1,0,0,0,1,1,1,1,1,0,1,0,0,0,1,1,1,1,1,0},/*B*/
		   {1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1},/*C*/
		   {1,1,1,1,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,0},/*D*/
		   {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1},/*E*/
		   {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0},/*F*/
		   {1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1},/*G*/
		   {1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1},/*H*/
		   {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},/*I*/
		   {1,1,1,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,1,1,1,1},/*J*/
		   
		   {1,0,0,0,1,1,0,0,1,0,1,1,1,0,0,1,0,0,1,0,1,0,0,0,1},/*K*/
		   {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1},/*L*/
		   {1,0,0,0,1,1,1,0,1,1,1,0,1,0,1,1,0,0,0,1,1,0,0,0,1},/*M*/
		   {1,0,0,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,1,1,0,0,0,1},/*N*/
		   {1,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1},/*O*/
		   {1,1,1,1,0,1,0,0,0,1,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0},/*P*/
		   {0,1,1,1,0,1,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,1},/*Q*/
		   {1,1,1,1,0,1,0,0,0,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,1},/*R*/
		   {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1},/*S*/
		   {1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},/*T*/
		   
		   {1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,1,1,1,0},/*U*/
		   {1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0},/*V*/
		   {1,0,0,0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,1},/*W*/
		   {1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1},/*X*/
		   {1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},/*Y*/
		   {1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0}/*Z*/};/*#26*/

	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Matrix patronesEntradas = new Matrix(patrones,26,25);
		//System.out.println(Main.matrix2String(patronesEntradas));
		
		ArrayList<int[]> resul = hash32.matrix2array(patronesEntradas);
		
		char letra = 'A';
		for(int i = 0; i < resul.size(); i++){
			int hash_i = hash32.hash32(resul.get(i));
			System.out.println("{"+ Integer.toBinaryString(hash_i) + "}, /*hash("+ letra + ")=" + hash_i + "*/" );
			letra++;
		}
	}

	public static ArrayList<int[]> matrix2array(Matrix mat){
		ArrayList<int[]> res = new ArrayList<int[]>();
		for(int i = 0 ; i < mat.getRowDimension(); i++){
			int arr[] = new int[5];
			patron2Array(mat,arr,i);
			System.out.println("arr-i= " + arr);
			res.add(i, arr);
		}
		return res;
	}
	

	static private void patron2Array(Matrix matrix, int[] arr, int fila) {
		for(int i = 0; i < 5 ; i++){
			String res = new String();
			for(int j = i*5 ; j < i*5 + 5  ; j++){
				res += matrix.get(fila,j) <= 0.0 ? "0" : "1";
			}
			arr[i] = Integer.parseInt(res,2);
		}		
		System.out.println("arri = " + arr[0] + " " + arr[1] + " " + arr[2] + " "  + arr[3] + " " + arr[4]);
	}

	static public int hash32(int[] grilla){
		int tbl_size = 29;
		int key_length = 5;  	
		int h = grilla[0];

		for (int i=1; i < key_length ; i++)
			h = (32 * h + grilla[i]) % tbl_size; 

		return h;
	}

	
}
